﻿namespace CardManagement
{
    using System;
    using System.Runtime.InteropServices;

    public class AcsDemoPublic
    {
        public static readonly string[] strDoorStatus = new string[] { "invalid", "sleep", "Normally open", "Normally close" };
        public static readonly string[] strVerify;
        public static readonly string[] strFingerType;
        public static readonly string[] strCardType;
        public const int MAX_DEVICES = 0x200;
        public const int TREE_ALL = 0;
        public const int DEVICE_LOGOUT = 1;
        public const int DEVICE_LOGIN = 2;
        public const int DEVICE_FORTIFY = 3;
        public const int DEVICE_ALARM = 4;
        public const int DEVICE_FORTIFY_ALARM = 5;
        public const int DOOR_COLSED = 6;
        public const int DOOR_OPEN = 7;
        public const int CARD_ON_LINE = 8;
        public const int CARD_OFF_LINE = 9;
        public const int DOOR_ALWAYSCOLSED = 6;
        public const int DOOR_ALWAYSOPEN = 7;
        public const int CHAN_ORIGINAL = 6;
        public const int CHAN_PLAY = 7;
        public const int CHAN_RECORD = 8;
        public const int CHAN_PLAY_RECORD = 9;
        public const int CHAN_ALARM = 10;
        public const int CHAN_PLAY_ALARM = 11;
        public const int CHAN_PLAY_RECORD_ALARM = 12;
        public const int CHAN_OFF_LINE = 13;
        public const int ALARM_INFO_T = 0;
        public const int OPERATION_SUCC_T = 1;
        public const int OPERATION_FAIL_T = 2;
        public const int PLAY_SUCC_T = 3;
        public const int PLAY_FAIL_T = 4;
        public const int REGIONTYPE = 0;
        public const int DEVICETYPE = 2;
        public const int CHANNELTYPE = 3;
        public const int DOORTYPE = 4;
        public const int CARDREADERTYPE = 6;
        public const int USERTYPE = 5;
        public const int ZERO_CHAN_INDEX = 500;
        public const int MIRROR_CHAN_INDEX = 400;

        static AcsDemoPublic()
        {
            string[] textArray2 = new string[0x17];
            textArray2[0] = "invalid";
            textArray2[1] = "sleep";
            textArray2[2] = "card and password";
            textArray2[3] = "card";
            textArray2[4] = "card or password";
            textArray2[5] = "fingerprint";
            textArray2[6] = "fingerprint and password";
            textArray2[7] = "fingerprint or card";
            textArray2[8] = "fingerprint and card";
            textArray2[9] = "fingerprint and card and password";
            textArray2[10] = "face or fingerprint or card or password";
            textArray2[11] = "face and fingerprint";
            textArray2[12] = "face and password";
            textArray2[13] = "face and card";
            textArray2[14] = "face";
            textArray2[15] = "work number and password";
            textArray2[0x10] = "fingerprint or password";
            textArray2[0x11] = "work number and fingerprint";
            textArray2[0x12] = "work number and fingerprint and password";
            textArray2[0x13] = "face and fingerprint and card";
            textArray2[20] = "face and password and fingerprint";
            textArray2[0x15] = "work number and face";
            textArray2[0x16] = "face or face and swipe card";
            strVerify = textArray2;
            strFingerType = new string[] { "Common fingerprint", "Stress fingerprint", "Patrol fingerprint", "Super fingerprint", "Dismissing fingerprint" };
            string[] textArray4 = new string[12];
            textArray4[0] = "unknown";
            textArray4[1] = "ordinary card";
            textArray4[2] = "disabled card";
            textArray4[3] = "black list card";
            textArray4[4] = "patrol card";
            textArray4[5] = "stress card";
            textArray4[6] = "super card";
            textArray4[7] = "guest card";
            textArray4[8] = "remove card";
            textArray4[9] = "employee card";
            textArray4[10] = "emergency card";
            textArray4[11] = "emergency management card";
            strCardType = textArray4;
        }

        public static bool CheckDate(CHCNetSDK.NET_DVR_SIMPLE_DAYTIME struItem) => 
            (((struItem.byHour <= 0x18) && (struItem.byMinute <= 0x3b)) && (struItem.bySecond <= 0x3b));

        public static bool CheckState(CHCNetSDK.NET_DVR_DATE struItem) => 
            (((struItem.wYear >= 0x7b2) && (struItem.byMonth <= 12)) && (struItem.byDay <= 0x1f));

        public enum DEMO_CHANNEL_TYPE
        {
            DEMO_CHANNEL_TYPE_INVALID = -1,
            DEMO_CHANNEL_TYPE_ANALOG = 0,
            DEMO_CHANNEL_TYPE_IP = 1,
            DEMO_CHANNEL_TYPE_MIRROR = 2
        }

        [StructLayout(LayoutKind.Sequential)]
        public struct LOCAL_LOG_INFO
        {
            public int iLogType;
            public string strTime;
            public string strLogInfo;
            public string strDevInfo;
            public string strErrInfo;
            public string strSavePath;
        }

        [StructLayout(LayoutKind.Sequential)]
        public struct PASSIVEDECODE_CHANINFO
        {
            public int lPassiveHandle;
            public int lRealHandle;
            public int lUserID;
            public int lSel;
            public IntPtr hFileThread;
            public IntPtr hFileHandle;
            public IntPtr hExitThread;
            public IntPtr hThreadExit;
            public string strRecordFilePath;
            public void init()
            {
                this.lPassiveHandle = -1;
                this.lRealHandle = -1;
                this.lUserID = -1;
                this.lSel = -1;
                this.hFileThread = IntPtr.Zero;
                this.hFileHandle = IntPtr.Zero;
                this.hExitThread = IntPtr.Zero;
                this.hThreadExit = IntPtr.Zero;
                this.strRecordFilePath = null;
            }
        }

        [StructLayout(LayoutKind.Sequential)]
        public struct PREVIEW_IFNO
        {
            public int iDeviceIndex;
            public int iChanIndex;
            public byte PanelNo;
            public int lRealHandle;
            public IntPtr hPlayWnd;
        }

        [StructLayout(LayoutKind.Sequential)]
        public struct STRU_CHANNEL_INFO
        {
            public int iDeviceIndex;
            public int iChanIndex;
            public AcsDemoPublic.DEMO_CHANNEL_TYPE iChanType;
            public int iChannelNO;
            [MarshalAs(UnmanagedType.ByValTStr, SizeConst=100)]
            public string chChanName;
            public uint dwProtocol;
            public uint dwStreamType;
            public uint dwLinkMode;
            public bool bPassbackRecord;
            public uint dwPreviewMode;
            public int iPicResolution;
            public int iPicQuality;
            public int lRealHandle;
            public bool bLocalManualRec;
            public bool bAlarm;
            public bool bEnable;
            public uint dwImageType;
            [MarshalAs(UnmanagedType.ByValTStr, SizeConst=0x10)]
            public string chAccessChanIP;
            public uint nPreviewProtocolType;
            public IntPtr pNext;
            public void init()
            {
                this.iDeviceIndex = -1;
                this.iChanIndex = -1;
                this.iChannelNO = -1;
                this.iChanType = AcsDemoPublic.DEMO_CHANNEL_TYPE.DEMO_CHANNEL_TYPE_INVALID;
                this.chChanName = null;
                this.dwProtocol = 0;
                this.dwStreamType = 0;
                this.dwLinkMode = 0;
                this.iPicResolution = 0;
                this.iPicQuality = 2;
                this.lRealHandle = -1;
                this.bLocalManualRec = false;
                this.bAlarm = false;
                this.bEnable = false;
                this.dwImageType = 6;
                this.chAccessChanIP = null;
                this.pNext = IntPtr.Zero;
                this.dwPreviewMode = 0;
                this.bPassbackRecord = false;
                this.nPreviewProtocolType = 0;
            }
        }

        [StructLayout(LayoutKind.Sequential)]
        public struct STRU_DEVICE_INFO
        {
            public int iDeviceIndex;
            public int lLoginID;
            public uint dwDevSoftVer;
            [MarshalAs(UnmanagedType.ByValTStr, SizeConst=100)]
            public string chLocalNodeName;
            [MarshalAs(UnmanagedType.ByValTStr, SizeConst=100)]
            public string chDeviceName;
            [MarshalAs(UnmanagedType.ByValTStr, SizeConst=130)]
            public string chDeviceIP;
            [MarshalAs(UnmanagedType.ByValTStr, SizeConst=130)]
            public string chDeviceIPInFileName;
            [MarshalAs(UnmanagedType.ByValTStr, SizeConst=0x20)]
            public string chLoginUserName;
            [MarshalAs(UnmanagedType.ByValTStr, SizeConst=0x20)]
            public string chLoginPwd;
            [MarshalAs(UnmanagedType.ByValTStr, SizeConst=130)]
            public string chDeviceMultiIP;
            [MarshalAs(UnmanagedType.ByValTStr, SizeConst=50)]
            public string chSerialNumber;
            public int iDeviceChanNum;
            public int iStartChan;
            public int iStartDChan;
            public int iDeviceType;
            public int iDiskNum;
            public int lDevicePort;
            public int iAlarmInNum;
            public int iAlarmOutNum;
            public int iAudioNum;
            public int iAnalogChanNum;
            public int iIPChanNum;
            public int iGroupNO;
            public bool bCycle;
            public bool bPlayDevice;
            public bool bVoiceTalk;
            [MarshalAs(UnmanagedType.ByValArray, SizeConst=8)]
            public int[] lAudioHandle;
            [MarshalAs(UnmanagedType.ByValArray, SizeConst=8)]
            public bool[] bCheckBroadcast;
            public int lFortifyHandle;
            public bool bAlarm;
            public int iDeviceLoginType;
            public uint dwImageType;
            public bool bIPRet;
            public int iEnableChanNum;
            public bool bDVRLocalAllRec;
            [MarshalAs(UnmanagedType.ByValArray, SizeConst=8)]
            public int[] lVoiceCom;
            public int lFirstEnableChanIndex;
            public int lTranHandle;
            public byte byZeroChanNum;
            public byte byMainProto;
            public byte bySubProto;
            public byte bySupport;
            public byte byStartDTalkChan;
            public byte byAudioInputChanNum;
            public byte byStartAudioInputChanNo;
            public byte byLanguageType;
            [MarshalAs(UnmanagedType.ByValArray, SizeConst=0x200, ArraySubType=UnmanagedType.Struct)]
            public AcsDemoPublic.STRU_CHANNEL_INFO[] pStruChanInfo;
            public CHCNetSDK.NET_DVR_IPPARACFG_V40[] pStruIPParaCfgV40;
            public CHCNetSDK.NET_DVR_IPALARMINCFG struAlarmInCfg;
            public CHCNetSDK.NET_DVR_IPALARMINCFG_V40 pStruIPAlarmInCfgV40;
            public CHCNetSDK.NET_DVR_IPALARMOUTCFG_V40 pStruIPAlarmOutCfgV40;
            public CHCNetSDK.NET_DVR_IPALARMOUTCFG struAlarmOutCfg;
            public IntPtr pNext;
            [MarshalAs(UnmanagedType.ByValArray, SizeConst=0x10, ArraySubType=UnmanagedType.Struct)]
            public AcsDemoPublic.STRU_CHANNEL_INFO[] struZeroChan;
            [MarshalAs(UnmanagedType.ByValTStr, SizeConst=0x10)]
            public string sSecretKey;
            public int iAudioEncType;
            [MarshalAs(UnmanagedType.ByValArray, SizeConst=0x100, ArraySubType=UnmanagedType.Struct)]
            public AcsDemoPublic.PASSIVEDECODE_CHANINFO[] struPassiveDecode;
            public byte bySupport1;
            public byte bySupport2;
            public byte byStartIPAlarmOutNo;
            public byte byMirrorChanNum;
            public ushort wStartMirrorChanNo;
            [MarshalAs(UnmanagedType.ByValArray, SizeConst=0x10, ArraySubType=UnmanagedType.Struct)]
            public AcsDemoPublic.STRU_CHANNEL_INFO[] struMirrorChan;
            public byte bySupport5;
            public byte bySupport7;
            public byte byCharaterEncodeType;
            public bool bInit;
            public byte byPanelNo;
            public int iDoorNum;
            [MarshalAs(UnmanagedType.ByValArray, SizeConst=0x300, ArraySubType=UnmanagedType.I1)]
            public int[] iDoorStatus;
            [MarshalAs(UnmanagedType.ByValArray, SizeConst=0x100, ArraySubType=UnmanagedType.ByValTStr)]
            public string[] sDoorName;
            public void Init()
            {
                this.iGroupNO = -1;
                this.iDeviceIndex = -1;
                this.lLoginID = -1;
                this.dwDevSoftVer = 0;
                this.chLocalNodeName = null;
                this.chDeviceName = null;
                this.chDeviceIP = null;
                this.chDeviceIPInFileName = null;
                this.chLoginUserName = null;
                this.chLoginPwd = null;
                this.chDeviceMultiIP = null;
                this.chSerialNumber = null;
                this.iDeviceChanNum = -1;
                this.iDoorNum = -1;
                this.iDoorStatus = new int[0x300];
                this.sDoorName = new string[0x100];
                this.iStartChan = 0;
                this.iDeviceType = 0;
                this.iDiskNum = 0;
                this.lDevicePort = 0x1f40;
                this.iAlarmInNum = 0;
                this.iAlarmOutNum = 0;
                this.iAnalogChanNum = 0;
                this.iIPChanNum = 0;
                this.byAudioInputChanNum = 0;
                this.byStartAudioInputChanNo = 0;
                this.bCycle = false;
                this.bPlayDevice = false;
                this.bVoiceTalk = false;
                this.lFortifyHandle = -1;
                this.bAlarm = false;
                this.iDeviceLoginType = 0;
                this.dwImageType = 1;
                this.bIPRet = false;
                this.pNext = IntPtr.Zero;
                this.lFirstEnableChanIndex = 0;
                this.lTranHandle = -1;
                this.byZeroChanNum = 0;
                this.sSecretKey = "StreamNotEncrypt";
                this.iAudioEncType = 0;
                this.bySupport1 = 0;
                this.bySupport2 = 0;
                this.bySupport5 = 0;
                this.bySupport7 = 0;
                this.byStartDTalkChan = 0;
                this.byLanguageType = 0;
                this.byCharaterEncodeType = 0;
                this.bInit = true;
                this.byPanelNo = 4;
            }
        }
    }
}

